package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortPoint {
    public static void main(String[] args) {
        List<Point> list=new ArrayList<>();
        list.add(new Point(2,4));
        list.add(new Point(5,6));
        list.add(new Point(8,7));
        list.add(new Point(54,5));
        list.add(new Point(23,6));
        list.add(new Point(233,224));
        list.add(new Point(44,66));
        System.out.println(list);
//        Collections.sort(list, new Comparator<Point>() {
//            @Override
//            public int compare(Point o1, Point o2) {
//                int i= o1.getX()*o1.getX()+o1.getY()*o1.getY();
//                int j=o2.getX()*o2.getX()+o2.getY()*o2.getY();
//                return i-j;
//            }
//        });
        Collections.sort(list,(o1,o2)->
                (o1.getX()*o1.getX()+o1.getY()*o1.getY())-(o2.getX()*o2.getX()+o2.getY()*o2.getY()));
        System.out.println(list);
        list.sort(new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                return o2.getY()-o1.getY();
            }
        });
        System.out.println(list);
        list.sort((s1,s2)->s1.getX()-s2.getX());
        System.out.println(list);
    }
}
